﻿using System;
using ServerApi.Controllers;
using ServerApi.Models;
using TuyennvLibrary.Utl;
namespace ServerApi.administrator
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        AccountModel accModel = new AccountModel();
        protected void Page_Load(object sender, EventArgs e)
        {
            AdminController.checkLogin(Session, Request, Response);
            //AdminController.checkPermission(Page, this.GetType(), Session, Request, Response);
        }

        protected void LbtnAccept_Click(object sender, EventArgs e)
        {
            try
            {
                Account obj = (Account)Session[AdminController.SESSION_USERCURRENT];
                if (obj.Oldpassword != txtoldPassword.Text)
                    throw new Exception("Không đúng mật khẩu");
                if (txtConfirm.Text != txtNewPass.Text)
                    throw new Exception("Confirm mật khẩu sai");
                obj.Oldpassword = txtNewPass.Text;
                obj.Password = Utilities.md5(obj.Oldpassword);

                if (accModel.ChangePassword(obj))
                    Utilities.Alert(Page, this.GetType(), "Bạn đã thay đổi mật khẩu thành công");
            }
            catch (Exception ex)
            {

                Utilities.Alert(Page, this.GetType(), ex.Message);
            }
        }

        protected void LbtnCancel_Click(object sender, EventArgs e)
        {

        }
    }
}